package org.oschina.plugin.topic;

import org.oschina.Constants;
import org.oschina.helper.topic.AbstractTopicListener;
import org.oschina.plugin.PluginHelper;
import org.oschina.plugin.bean.PluginStatusSyncBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 插件状态同步处理
 */
@Component
public class PluginStatusSyncTopic extends AbstractTopicListener {

	private final static Logger logger=LoggerFactory.getLogger(PluginStatusSyncTopic.class);
	
	@Autowired
	private PluginHelper pluginHelper;

	@Override
	public String getKey()
	{
		return Constants.TOPIC_PLUGIN_STATUS_SYNC;
	}

	@Override
	public Class getType()
	{
		return PluginStatusSyncBean.class;
	}

	@Override
	public synchronized void handle(Object message)
	{
		PluginStatusSyncBean bean=(PluginStatusSyncBean) message;
		pluginHelper.setEnabled(bean.getId(), bean.getEnabled());
		logger.info("ID为 '{}' 的插件状态同步成功",bean.getId());
	}
}